package userHelp

import (
	myCfg "common/config"
	myredis "common/redis"
)

// 玩家控制表
type MemberControllerButton struct {
	Uid                        string  `json:"uid" db:"uid"`
	GameButton                 int8    `json:"game_button" db:"game_button"`                                       //游戏开关
	WithdrawButton             int8    `json:"withdraw_button" db:"withdraw_button"`                               //提现开关
	TaxButton                  int8    `json:"tax_button" db:"tax_button"`                                         //抽税开关
	AutoWithdrawButton         int8    `json:"auto_withdraw_button" db:"auto_withdraw_button"`                     //自动出款开关
	ControlCodeButton          int8    `json:"control_code_button" db:"control_code_button"`                       //控码开关 控制个人输赢打码
	UnbindButton               int8    `json:"unbind_button" db:"unbind_button"`                                   //掉绑开关
	IsBloger                   int8    `json:"is_bloger" db:"is_bloger"`                                           //是否博主
	WinFlowMultiple            float64 `json:"win_flow_multiple" db:"win_flow_multiple"`                           //赢打码%
	LoseFlowMultiple           float64 `json:"lose_flow_multiple" db:"lose_flow_multiple"`                         //输打码%
	FakePgButton               int8    `json:"fake_pg_button" db:"fake_pg_button"`                                 //假pg开关 1=开，2=关
	CommiButton                int8    `json:"commi_button" db:"commi_button"`                                     //佣金开关 1=开，2=关
	RtpcontrolWay              int8    `json:"rtp_control_way" db:"rtp_control_way"`                               //RTP控制方式 0 默认 1 关闭 2 手动
	Rtp                        int8    `json:"rtp" db:"rtp"`                                                       //
	DisbindControl             string  `json:"disbind_control" db:"disbind_control"`                               //掉绑控制
	RechargeButton             int     `json:"recharge_button" db:"recharge_button"`                               //下级充值分成开关 0 关闭 1 开启
	RechargeShareType          int     `json:"recharge_share_type" db:"recharge_share_type"`                       //充值分成奖励类型  0无充值分成奖励 1首冲 2复冲 3首冲 复冲都有奖励
	RechargeShareWagedReq      int     `json:"recharge_share_waged_req" db:"recharge_share_waged_req"`             //充值分成奖励 打码量要求
	RechargeShareRate          string  `json:"recharge_share_rate" db:"recharge_share_rate"`                       //充值分成奖励配置
	RechargeShareRateF         string  `json:"recharge_share_rate_f" db:"recharge_share_rate_f"`                   //复值分成奖励配置
	CommiSwitchSyncSub         int8    `json:"commi_switch_sync_sub" db:"commi_switch_sync_sub"`                   //佣金开关是否同步下级 0不同步 1 同步
	RechargeShareSwitchSyncSub int8    `json:"recharge_share_switch_sync_sub" db:"recharge_share_switch_sync_sub"` //充值分成是否同步下级 0不同步 1 同步
	SandbagAmountMax           float64 `json:"sandbag_amount_max" db:"sandbag_amount_max"`                         //放水金额
	SandbagSwitch              int8    `json:"sandbag_switch" db:"sandbag_switch"`                                 //放水开关
	RechargeHiddenSwitch       int8    `json:"recharge_hidden_switch" db:"recharge_hidden_switch"`                 //复充订单开关 1开 2关
	SycDisbindlv1              string  `json:"syc_disbind_lv1" db:"syc_disbind_lv1"`                               //同步掉绑1级开关  00,01,10,11
	SycDisbindlv2              string  `json:"syc_disbind_lv2" db:"syc_disbind_lv2"`                               //同步掉绑1级开关  00,01,10,11
	SycDisbindlv3              string  `json:"syc_disbind_lv3" db:"syc_disbind_lv3"`                               //同步掉绑1级开关  00,01,10,11
	Fake_pp_rtp                int     `json:"fake_PP_rtp" db:"fake_PP_rtp"`                                       //
	Fake_JDB_rtp               int     `json:"fake_JDB_rtp" db:"fake_JDB_rtp"`                                     //
	Fake_JILI_rtp              int     `json:"fake_JILI_rtp" db:"fake_JILI_rtp"`                                   //

	//充值隐藏相关
	SycChargeHiddenlv1 string `json:"syc_charge_hidden_lv1" db:"syc_charge_hidden_lv1"` //充值隐藏1级开关 00,01,10,11
	SycChargeHiddenlv2 string `json:"syc_charge_hidden_lv2" db:"syc_charge_hidden_lv2"` //充值隐藏1级开关 00,01,10,11
	SycChargeHiddenlv3 string `json:"syc_charge_hidden_lv3" db:"syc_charge_hidden_lv3"` //充值隐藏1级开关 00,01,10,11

	ChargeHiddenButton int `json:"charge_hidden_button" db:"charge_hidden_button"` //充值隐藏控制开关 1开 2关

	ChargeHiddenControlS string `json:"charge_hidden_control_s" db:"charge_hidden_control_s"` //首充隐藏控制
	ChargeHiddenControlF string `json:"charge_hidden_control_f" db:"charge_hidden_control_f"` //首充隐藏控制

	ChargeHiddenButtonS int `json:"charge_hidden_button_s" db:"charge_hidden_button_s"` //充值隐藏控制开关 1开 2关
	ChargeHiddenButtonF int `json:"charge_hidden_button_f" db:"charge_hidden_button_f"` //充值隐藏控制开关 1开 2关
}

var g_tbl_member_controller_button = "tbl_member_controller_button:"

type UserButton struct{}

var G_UserButton UserButton

const (
	ButtonOpen  = 1 //功能启用
	ButtonClose = 2 //功能关闭
)

func (that *UserButton) IsBloger(uid string) int {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldInt(uid, g_tbl_member_controller_button+"is_bloger")
}

func (that *UserButton) GetFakePPRtp(uid string) int {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldInt(uid, g_tbl_member_controller_button+"fake_PP_rtp")
}

func (that *UserButton) GetFakeJDBRtp(uid string) int {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldInt(uid, g_tbl_member_controller_button+"fake_JDB_rtp")
}

func (that *UserButton) GetFakeJILIRtp(uid string) int {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldInt(uid, g_tbl_member_controller_button+"fake_JILI_rtp")
}

// 掉绑同步是否向上寻找 1 向上一级寻找  0 不寻找
func (that *UserButton) GetEnableSycDisbindlv1(uid string) int {
	LoadUserToRedis(uid)
	SycDisbind := myredis.GetUserFieldString(uid, g_tbl_member_controller_button+"syc_disbind_lv1")

	DisbindByte := []byte(SycDisbind)

	if len(DisbindByte) < 3 {
		return 0
	}

	return int(DisbindByte[2] - 0x30)
}

func (that *UserButton) GetEnableSycDisbindlv2(uid string) int {
	LoadUserToRedis(uid)
	SycDisbind := myredis.GetUserFieldString(uid, g_tbl_member_controller_button+"syc_disbind_lv2")

	DisbindByte := []byte(SycDisbind)

	if len(DisbindByte) < 3 {
		return 0
	}

	return int(DisbindByte[2] - 0x30)
}
func (that *UserButton) GetEnableSycDisbindlv3(uid string) int {
	LoadUserToRedis(uid)
	SycDisbind := myredis.GetUserFieldString(uid, g_tbl_member_controller_button+"syc_disbind_lv3")

	DisbindByte := []byte(SycDisbind)

	if len(DisbindByte) < 3 {
		return 0
	}

	return int(DisbindByte[2] - 0x30)
}

// 掉绑同步开关
func (that *UserButton) GetSycDisbindlv1(uid string) int {
	LoadUserToRedis(uid)
	SycDisbind := myredis.GetUserFieldString(uid, g_tbl_member_controller_button+"syc_disbind_lv1")

	DisbindByte := []byte(SycDisbind)

	if len(DisbindByte) == 0 {
		return 0
	}

	return int(DisbindByte[0] - 0x30)
}

func (that *UserButton) GetSycDisbindlv2(uid string) int {
	LoadUserToRedis(uid)
	SycDisbind := myredis.GetUserFieldString(uid, g_tbl_member_controller_button+"syc_disbind_lv2")

	DisbindByte := []byte(SycDisbind)

	if len(DisbindByte) == 0 {
		return 0
	}

	return int(DisbindByte[0] - 0x30)
}

func (that *UserButton) GetSycDisbindlv3(uid string) int {
	LoadUserToRedis(uid)
	SycDisbind := myredis.GetUserFieldString(uid, g_tbl_member_controller_button+"syc_disbind_lv3")

	DisbindByte := []byte(SycDisbind)

	if len(DisbindByte) == 0 {
		return 0
	}

	return int(DisbindByte[0] - 0x30)
}

// 判断玩家是否处于放水状态
func (that *UserButton) IsSandbagState(uid string) bool {
	LoadUserToRedis(uid)
	if that.GetSandbagSwitch(uid) == 0 {
		return false
	}

	SandbagAmountMax := that.GetSandbagAmountMax(uid)
	if SandbagAmountMax <= GetUserSandbagAmount(uid) {
		return false
	}

	return true
}

func (that *UserButton) CloseSandbagSwitch(uid string) {
	LoadUserToRedis(uid)
	myredis.SetUserFieldValue(uid, g_tbl_member_controller_button+"sandbag_switch", "0")
}

func (that *UserButton) GetSandbagAmountMax(uid string) float64 {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldFloat64(uid, g_tbl_member_controller_button+"sandbag_amount_max")
}

// 游戏开关
func (that *UserButton) GetSandbagSwitch(uid string) int {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldInt(uid, g_tbl_member_controller_button+"sandbag_switch")
}

func (that *UserButton) GetRechargeHiddenSwitch(uid string) int {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldInt(uid, g_tbl_member_controller_button+"recharge_hidden_switch")
}

// 赢打码%
func GetValidWagedFlowMultiple(uid string, betAmount float64) float64 {
	LoadUserToRedis(uid)

	var WagedFlow float64 = 1.00
	CodeButton := myredis.GetUserFieldFloat64(uid, g_tbl_member_controller_button+"control_code_button")
	if CodeButton == 2 ||
		myCfg.GetGameCfgInt(myCfg.CfgGlobalWagedRateSwitch) == 0 {
		return WagedFlow
	}

	//有控码
	userTotalWage := GetTotalWaged(uid)
	if userTotalWage > myCfg.GetGameCfgFloat64(myCfg.CfgWagedDisCountCondition) {
		WagedFlow = myCfg.GetValidWagedRateMul(betAmount)
	}

	return WagedFlow
}

// 游戏开关
func (that *UserButton) GetGameButton(uid string) int {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldInt(uid, g_tbl_member_controller_button+"game_button")
}

// 提现开关
func (that *UserButton) GetWithdraw(uid string) int {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldInt(uid, g_tbl_member_controller_button+"withdraw_button")
}

// 抽税开关
func (that *UserButton) GetTax(uid string) int {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldInt(uid, g_tbl_member_controller_button+"tax_button")
}

func (that *UserButton) GetFakePGRtp(uid string) int {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldInt(uid, g_tbl_member_controller_button+"rtp")
}

func (that *UserButton) GetRtpControlWay(uid string) int {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldInt(uid, g_tbl_member_controller_button+"rtp_control_way")
}

func (that *UserButton) GetDisbindControl(uid string) string {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldString(uid, g_tbl_member_controller_button+"disbind_control")
}

// 自动出款
func (that *UserButton) GetAutoWithdraw(uid string) int {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldInt(uid, g_tbl_member_controller_button+"auto_withdraw_button")
}

// 控制个人输赢打码
func (that *UserButton) GetControlCode(uid string) int {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldInt(uid, g_tbl_member_controller_button+"control_code_button")
}

func (that *UserButton) GetUnbind(uid string) int {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldInt(uid, g_tbl_member_controller_button+"unbind_button")
}

func (that *UserButton) GetFakePgButton(uid string) int {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldInt(uid, g_tbl_member_controller_button+"fake_pg_button")
}

func (that *UserButton) GetCommiButton(uid string) int {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldInt(uid, g_tbl_member_controller_button+"commi_button")
}

func (that *UserButton) GetCommiSwitchSyncSub(uid string) int {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldInt(uid, g_tbl_member_controller_button+"commi_switch_sync_sub")
}

func (that *UserButton) GetRechargeShareSwitchSyncSub(uid string) int {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldInt(uid, g_tbl_member_controller_button+"recharge_share_switch_sync_sub")
}

func (that *UserButton) SetRtp(uid string, rtp int) {
	LoadUserToRedis(uid)
	myredis.SetUserFieldValueByInt(uid, g_tbl_member_controller_button+"rtp", rtp)
}

func (that *UserButton) SetRtpControlWay(uid string, rtpControlWay int) {
	LoadUserToRedis(uid)
	myredis.SetUserFieldValueByInt(uid, g_tbl_member_controller_button+"rtp_control_way", rtpControlWay)
}

func (that *UserButton) SetDisbindControl(uid string, disableControl string) {
	LoadUserToRedis(uid)
	myredis.SetUserFieldValue(uid, g_tbl_member_controller_button+"disbind_control", disableControl)
}

// 下级充值分成开关
func (that *UserButton) GetRechargeButton(uid string) int {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldInt(uid, g_tbl_member_controller_button+"recharge_button")
}

// 充值分成奖励类型
func (that *UserButton) GetRechargeShareType(uid string) int {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldInt(uid, g_tbl_member_controller_button+"recharge_share_type")
}

// 充值分成奖励
func (that *UserButton) GetRechargeShareWagedReq(uid string) int {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldInt(uid, g_tbl_member_controller_button+"recharge_share_waged_req")
}

// 充值分成奖励配置
func (that *UserButton) GetRechargeShareRate(uid string) string {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldString(uid, g_tbl_member_controller_button+"recharge_share_rate")
}

// 复冲分成奖励配置
func (that *UserButton) GetRRechargeShareRateF(uid string) string {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldString(uid, g_tbl_member_controller_button+"recharge_share_rate_f")
}

/////充值隐藏相关

func (that *UserButton) GetEnableSycChargeHiddenlv1(uid string) int {
	LoadUserToRedis(uid)
	SycDisbind := myredis.GetUserFieldString(uid, g_tbl_member_controller_button+"syc_charge_hidden_lv1")

	DisbindByte := []byte(SycDisbind)

	if len(DisbindByte) < 3 {
		return 0
	}

	return int(DisbindByte[2] - 0x30)
}

func (that *UserButton) GetEnableSycChargeHiddenlv2(uid string) int {
	LoadUserToRedis(uid)
	SycDisbind := myredis.GetUserFieldString(uid, g_tbl_member_controller_button+"syc_charge_hidden_lv2")

	DisbindByte := []byte(SycDisbind)

	if len(DisbindByte) < 3 {
		return 0
	}

	return int(DisbindByte[2] - 0x30)
}
func (that *UserButton) GetEnableSycChargeHiddenlv3(uid string) int {
	LoadUserToRedis(uid)
	SycDisbind := myredis.GetUserFieldString(uid, g_tbl_member_controller_button+"syc_charge_hidden_lv3")

	DisbindByte := []byte(SycDisbind)

	if len(DisbindByte) < 3 {
		return 0
	}

	return int(DisbindByte[2] - 0x30)
}

func (that *UserButton) GetSycChargeHiddenlv1(uid string) int {
	LoadUserToRedis(uid)
	SycDisbind := myredis.GetUserFieldString(uid, g_tbl_member_controller_button+"syc_charge_hidden_lv1")

	DisbindByte := []byte(SycDisbind)

	if len(DisbindByte) == 0 {
		return 0
	}

	return int(DisbindByte[0] - 0x30)
}

func (that *UserButton) GetSycChargeHiddenlv2(uid string) int {
	LoadUserToRedis(uid)
	SycDisbind := myredis.GetUserFieldString(uid, g_tbl_member_controller_button+"syc_charge_hidden_lv2")

	DisbindByte := []byte(SycDisbind)

	if len(DisbindByte) == 0 {
		return 0
	}

	return int(DisbindByte[0] - 0x30)
}

func (that *UserButton) GetSycChargeHiddenlv3(uid string) int {
	LoadUserToRedis(uid)
	SycDisbind := myredis.GetUserFieldString(uid, g_tbl_member_controller_button+"syc_charge_hidden_lv3")

	DisbindByte := []byte(SycDisbind)

	if len(DisbindByte) == 0 {
		return 0
	}

	return int(DisbindByte[0] - 0x30)
}

// 充值隐藏开关
func (that *UserButton) GetChargeHiddenButton(uid string) int {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldInt(uid, g_tbl_member_controller_button+"charge_hidden_button")
}

// 首冲隐藏控制json 格式
func (that *UserButton) GetChargeHiddenControlS(uid string) string {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldString(uid, g_tbl_member_controller_button+"charge_hidden_control_s")
}

// 复冲隐藏控制json 格式
func (that *UserButton) GetChargeHiddenControlF(uid string) string {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldString(uid, g_tbl_member_controller_button+"charge_hidden_control_f")
}

// 首冲隐藏控制开关
func (that *UserButton) GetChargeHiddenSwitchS(uid string) int {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldInt(uid, g_tbl_member_controller_button+"charge_hidden_button_s")
}

// 复冲隐藏控制开关
func (that *UserButton) GetChargeHiddenSwitchF(uid string) int {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldInt(uid, g_tbl_member_controller_button+"charge_hidden_button_f")
}
